#include"server.hpp"


void OnConnected(const PtrConnection& conn)
{
     DBG_LOG("NEW Connection:%p",conn.get());
}

void OnClosed(const PtrConnection& conn)
{
     DBG_LOG("Close Connection:%p",conn.get());
}

void OnMessage(const PtrConnection& conn,Buffer* buf)
{
//    if(lst_fd != conn->Fd())
//      DBG_LOG("On Message..");
   DBG_LOG("%s",buf->ReadPos());
   buf->MoveReadIdx(buf->ReadAbleSize());
   string str = "Hello World";
   conn->Send(str.c_str(),str.size());
//    conn->ShutDown();//测试收到一次就关闭
}

int main()
{
    TcpServer server(8081);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);
    server.SetMessageCallBack(OnMessage);
    server.SetConnectedCallBack(OnConnected);
    server.SetCloseCallBack(OnClosed);
    server.Start();
    return 0;
}